package de.fhhannover.inform.wari.grp8.gui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;

/**
 * @author Oleg Starodubtsev created on 10.11.2008 updated by Shanmugaesan on
 *         30.11.08 Function deactivateKIs() added.
 */

public class Menu implements ActionListener {
	private Gui_Controller mGc;
	private JMenuBar mMenuBar;
	private JMenu mSpielmenu;
	private JMenu mHilfemenu;
	private JMenu mKImenu;
	private JMenuItem mNewGame;
	private JMenuItem mExit;
	private JMenuItem mSpielRegel;
	private JMenuItem mKIA_jmi;
	private JMenuItem mKIB_jmi;
	private JMenuItem mAbout;

	public Menu(Gui_Controller gc) {
		mGc = gc;
		initMenu();
		settingMenu();
	}

	public void initMenu() {
		mMenuBar = new JMenuBar();
		mSpielmenu = new JMenu("Spiel");
		mHilfemenu = new JMenu("Hilfe");
		mKImenu = new JMenu("KIs");
		mNewGame = new JMenuItem("Neues Spiel");
		mExit = new JMenuItem("Beenden");
		mSpielRegel = new JMenuItem("Spielregeln");
		mKIA_jmi = new JMenuItem("KI A");
		mKIB_jmi = new JMenuItem("KI B");
		mAbout = new JMenuItem("Impressum");
	}

	public void settingMenu() {
		mSpielmenu.add(mNewGame);
		mNewGame.addActionListener(this);
		mSpielmenu.add(mExit);
		mExit.addActionListener(this);
		mHilfemenu.add(mSpielRegel);
		mSpielRegel.addActionListener(this); // Sofia
		mHilfemenu.add(mAbout);
		mAbout.addActionListener(this); // Michael
		mKImenu.add(mKIA_jmi);
		mKImenu.add(mKIB_jmi);
		mKIA_jmi.addActionListener(this);
		mKIB_jmi.addActionListener(this);
		mMenuBar.add(mSpielmenu);
		mMenuBar.add(mKImenu);
		mMenuBar.add(mHilfemenu);

		// mMenuBar.setBackground(mGc.getColor());
	}

	public JMenuBar getMenuBar() {
		return mMenuBar;
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		Object source = e.getSource();
		if (source == mNewGame) {
			mGc.newGame();
		} else if (source == mExit) {
			mGc.endGame();
		} else if (source == mSpielRegel) { // Sofia
			mGc.openHelp();
		} else if (source == mKIA_jmi) {
			mGc.chooseKI(true);
		} else if (source == mKIB_jmi) {
			mGc.chooseKI(false);
		} else if (source == mAbout) {
			mGc.openAbout();

		}
	}

}
